{% extends "osr-theme-w/pages/based/based.html" %}
{% block title %}{{_("首页")}}-{% endblock %}
{% block osr_top_img %}{% endblock %}
{% block content %}
<div id="app" v-cloak>
    <!--#####################################################################
    说明:Home页面封面大图, 这是'home-display-cover-', image类型.
     可在osroom管理端->主题展示设置->图文里添加或修改，删除
    ######################################################################-->
     <div class="osr-bg-cover" :style="'background: url('+home_display_cover.url+') no-repeat center center fixed;'">
     </div>
    <div class="col-xs-12 osr-white-text" style="text-align:center;position:absolute;height:auto;z-indent:2;top:180px;">
        <h1 v-if="home_display_cover.title">{[home_display_cover.title]}</h1>
        <div v-if="home_display_cover.text" v-html="home_display_cover.text_html"></div>
        <div v-if="home_display_cover.code" v-html="home_display_cover.code"></div>
    </div>

    <div class="osr-content-wt ">
        {% include 'osr-theme-w/pages/_index_s2.html' %}
    </div>
    <div id="content" class="row osr-page">

        {% include 'osr-theme-w/pages/_index_s3.html' %}
    </div>
</div>
<!--<script src="/theme/osr-theme-w/static/js/markdown/marked.min.js?v={{g.site_global.site_config.STATIC_FILE_VERSION}}"></script>-->
<!--<link href="/theme/osr-theme-w/static/css/highlight-style-github.css?v={{g.site_global.site_config.STATIC_FILE_VERSION}}" rel="stylesheet">-->
<!--<script src="/theme/osr-theme-w/static/js/highlight.js?v={{g.site_global.site_config.STATIC_FILE_VERSION}}"></script>-->
<script>

    var vue = new Vue({
      el: '#app',
      delimiters:['{[', ']}'],
      data:{
            carousel:[{}],
            home_display:null,
            home_display_img: null,
            home_display_cover: null,
            display_tag:0,
            posts:{datas:[]},
            sort:"t-desc",
            pages:[],
            page:1,
            tags:{},
            img_w_h:"?w=0&h=120",
            colors:[]
      },
      filters: {
            formatDate: function (time) {
              return irrformatDate(time, "yyyy-MM-dd hh:mm");
            }
      }
    })

    // 加载完页面执行
    $(document).ready(function(){
        vue.colors = osr_colors();
        get_global();
        get_posts(vue.page, vue.sort);
        get_post_tags();
    })

    function get_global(){
        var conditions = [
             {
                type:"text",
                name_regex:"home-display-[0-9]+",
                result_key:"home_display"
             },
            {
                type:"text",
                name_regex:"display_tag",
                result_key:"display_tag"
             },
            {
                type:"image",
                name_regex:"home-display-img-[0-9]+",
                result_key:"home_display_img"
             },
            {
                type:"image",
                name_regex:"home-display-cover-[0-9]+",
                result_key:"home_display_cover"
             }
        ];
        var d ={
            conditions:JSON.stringify(conditions),
            theme_name:"osr-theme-w"
        }
        var result = osrHttp("GET","/api/global/theme-data/display", d, args={not_prompt:true});
        result.then(function (r) {
            vue.display_tag =  r.data.medias.display_tag.length===0?null:r.data.medias.display_tag[0];
            vue.home_display = r.data.medias.home_display;
            vue.home_display = vue.home_display.length === 0?null:vue.home_display;
            vue.home_display_img = r.data.medias.home_display_img;
            vue.home_display_img = vue.home_display_img.length === 0?null:vue.home_display_img;

            vue.home_display_cover = r.data.medias.home_display_cover.length === 0?null:r.data.medias.home_display_cover[0];
        });
    }

    //获取
    function get_posts(page, sort){

        vue.sort = sort;
        vue.page = page;
        if(sort=="t-desc"){
            sort = [{"issue_time":-1},{"update_time":-1}];
        }else if(sort=="t-asc"){
           sort = [{"issue_time":1},{"update_time":1}];
        }else{
            sort = [{"like": -1}, {"comment_num": -1}, {"pv": -1},{"issue_time": -1}];
        }

        d = {
            page:page,
            pre:6,
            status:"is_issued",
            sort:JSON.stringify(sort),
            unwanted_fields:JSON.stringify(["content", "imgs"])
        }

        var result = osrHttp("GET","/api/post", d, args={not_prompt:true});
        result.then(function (r) {
            $.each(r.data.posts.datas, function(index, value) {
                if(value["tags"].length>3 && value.brief_content.length>25){
                    value.brief_content = value.brief_content.slice(0, 25)
                }
                // if(value.editor=="markdown"){
                //     r.data.posts.datas[index]["brief_content"] = marked(value.brief_content);
                // }
            });
            vue.pages = paging(page_total=r.data.posts.page_total, current_page=r.data.posts.current_page);
            if(vue.page!=1){
                var old_datas = vue.posts.datas;
                vue.posts = r.data.posts;
                $.merge(old_datas, r.data.posts.datas);
                vue.posts.datas = old_datas;
            }else{
                vue.posts = r.data.posts;
            }
        });
    }

    function get_post_tags(){
        var d ={
            limit:30,
            last_days:360
        }

        var result = osrHttp("GET","/api/post/tags", d, args={not_prompt:true});
        result.then(function (r) {
            vue.tags = r.data.tags;
        });
    }

</script>

{% endblock %}
